﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Bowerbird.Core.Storage;
using System.Transactions;

namespace Core.Tests.Storage
{
    /// <summary>
    /// Summary description for Users
    /// </summary>
    [TestClass]
    public class Users
    {
        [TestMethod]
        public void RegisterNewUser()
        {
            using (var scope = new TransactionScope())
            {
                string identityProvider = "test";
                string nameIdentifier = "test";
                string name = "test";

                User user = UserRepository.GetByNameIdentifier(identityProvider, nameIdentifier);

                if (user != null)
                    RepositoryBase<User>.Delete(user);

                user = UserRepository.Register(identityProvider, nameIdentifier, name);

                Assert.AreEqual(identityProvider, user.IdentityProvider);
                Assert.AreEqual(nameIdentifier, user.NameIdentifier);
                Assert.AreEqual(name, user.Name);

                User user2 = UserRepository.GetByNameIdentifier(identityProvider, nameIdentifier);

                Assert.AreEqual(user.Id, user2.Id);
                Assert.AreEqual(identityProvider, user2.IdentityProvider);
                Assert.AreEqual(nameIdentifier, user2.NameIdentifier);
                Assert.AreEqual(name, user2.Name);

            }
        }
    }
}
